//
//  CPHomeTopView.swift
//  cockpit
//
//  Created by Haijun Si on 2020/7/9.
//  Copyright © 2020 chenganrt. All rights reserved.
//

import UIKit

class CPHomeTopView: UIView {

    var dataArray:[CPHomeMoreTypeModel]? {
        didSet {
            if let dataArr = dataArray ,dataArr.count > 0 {
                self.moreView.dataArray = dataArr
            }
        }
    }
    
    var  bannerImgs : [CPHomeCycleModel]? {
        didSet {
            if let bannerImgModels = bannerImgs ,bannerImgModels.count > 0 {
                self.cycleView.bannerImgs = bannerImgModels
            }
        }
    }
    
    private let cycleView = CPCycleView(frame: CGRect(x: 0, y: 0, width: CPScreenWidth, height: 220))
    private let moreView = CPHomeMoreTypeView(frame: CGRect(x: 0, y: 220, width: CPScreenWidth, height: CPScreenWidth/4.0))
    
    public func getViewHeight() -> CGFloat {
        return self.moreView.getViewHeight() + 220
    }
    
    override init(frame: CGRect) {
        super.init(frame:frame)
        self.addSubview(self.cycleView)
        self.addSubview(self.moreView)
        if let dataArr = dataArray ,dataArr.count > 0 {
            self.moreView.frame = CGRect(x: 0, y: 220, width: CPScreenWidth, height: CPScreenWidth/4.0 * CGFloat((dataArr.count/4 + 1)))
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
